"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025-10-13
"""
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64


def aes_encrypt(key, iv, data):
    cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8'))
    padded = pad(data.encode('utf-8'), AES.block_size)
    res = cipher.encrypt(padded)
    print(res)

    return base64.b64encode(res).decode('utf-8')


def aes_decrypt(key, iv, data):
    cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8'))
    item = base64.b64decode(data)
    print(item)
    padded = cipher.decrypt(item)
    decode = unpad(padded, AES.block_size)
    return decode.decode('utf-8')


key = "132abc785zkb9m3t"
iv = '13525233df4'
iv = iv.ljust(16)
print(aes_encrypt(key, iv, '123456'))

print(aes_decrypt(key, iv, 'OUPppf32GBEI2i3q6xMmmQ=='))
